package org.example.controller;

import org.example.domain.User;
import org.example.domain.esdomain.UserIndex;
import org.example.pojo.PageParams;
import org.example.result.ResultData;
import org.example.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户操作
 */
@RestController
@RequestMapping(value = "/userOperate")
public class UserController {

    @Autowired
    private IUserService userService;

    /**
     * 查询不同类型的用户
     */
    @PostMapping(value = "/getUserListByIdentifying")
    public ResultData getUserListByIdentifying(@RequestBody PageParams<UserIndex> params) {
        return ResultData.success(userService.getUserListByIdentifying(params));
    }

    /**
     * 查询详细信息
     */
    @GetMapping(value = "/getUserById")
    public ResultData getUserById(@RequestParam(value = "id") String id) {
        return ResultData.success(userService.getUserDetail(id));
    }

    /**
     * 新增用户
     */
    @PostMapping(value = "/addUser")
    public ResultData addUser(@RequestBody User user) {
        return ResultData.success(userService.addUser(user));
    }

    /**
     * 修改用户
     */
    @PostMapping(value = "/editUserById")
    public ResultData editUserById(@RequestBody User user) {
        return ResultData.success(userService.editUser(user));
    }

    /**
     * 批量删除用户
     */
    @GetMapping(value = "/delUserByIds")
    public ResultData delUserByIds(@RequestParam(value = "ids") String ids) {
        return ResultData.success(userService.removeUser(ids));
    }

    /**
     * 获取app用户详细信息
     */
    @GetMapping(value = "/getAppUserDetail")
    public ResultData getAppUserDetail(@RequestParam(value = "id") String id) {
        return ResultData.success(userService.getAppUserDetailData(id));
    }
}
